package com.ketai.web;

import com.ketai.common.MessageConstant;
import com.ketai.service.ApplicationService;
import com.ketai.service.impl.ApplicationServiceImpl;
import com.ketai.util.Pages;
import com.ketai.util.SendUtil;
import com.ketai.vo.ApplicationVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:长沙科泰梦想学院-蓝色小药丸
 * @Mission:打造演说·创客型跨境电商与互联网人才
 * @Description:
 * @Date:Create In 2022/8/9 22:05
 **/

@WebServlet("/admin/app")
public class ApplicationServlet extends HttpServlet {

    ApplicationService service = new ApplicationServiceImpl();

    @Override
    protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String opr = req.getParameter("opr");
        if (opr.equals("list")) {
            String title = req.getParameter("title");
            String checked=req.getParameter("checked");
            String curr = req.getParameter("page");
            String limit = req.getParameter("limit");
            Pages<ApplicationVo> pages = service.findPage(title,checked, curr, limit);
            //调用工具类 返回数据给前端
            SendUtil.SendPageJson(resp, pages);


        }else if("check".equals(opr)){

            String  id= req.getParameter("id");
            String open= req.getParameter("open");
            String  desc = req.getParameter("desc");
            //审核人信息  后续从session中获取
            String pid = "1";
            int result= service.checkedActity(id,open,desc,pid);
            if(result>0){
                SendUtil.Sendjson(resp, MessageConstant.APPLY_CHECK_SUCCESS);
            }else {
                SendUtil.Sendjson(resp,MessageConstant.APPLY_CHECK_ERROR);
            }

        }


    }
}
